<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>Database - Query Builder Insert - Fuel Documentation</title>
	<link href="../../assets/css/main.css" media="screen" rel="stylesheet" />
	<script type="text/javascript" src="../../assets/js/jquery-1.4.4.min.js"></script>
	<script type="text/javascript" src="../../assets/js/nav.js"></script>
	<script type="text/javascript" src="../../assets/js/highlight.pack.js"></script>
	<script type="text/javascript">
		$(function() {
			show_nav('classes', '../../');
		});
		hljs.tabReplace = '    ';
		hljs.initHighlightingOnLoad();
	</script>
</head>
<body>

	<header>
		<h1>Fuel Documentation</h1>
	</header>

	<div id="main-nav"></div>

	<section id="content">
		<h2 id="introduction">Query_Builder_Insert class (extends <a href="qb_where.html">Query_Builder_Where</a></h2>
		
		<p>
			The Query_Builder_Insert class handles all the insert operations for the query building process. It extends the
			Query_Builder_Where class, so all the methods are inherrited.
		</p>
		
		<h2 id="methods">Methods</h2>

		<article>
			<h4 id="method_table">table($table)</h4>
			<p>The <strong>table</strong> method sets/changes the table to insert into.</p>
			<table class="method">
				<tbody>
					<tr>
						<th>Static</th>
						<td>No</td>
					</tr>
					<tr>
						<th>Parameters</th>
						<td>
							<table class="parameters">
								<tr>
									<th>Param</th>
									<th>Type</th>
									<th>Default</th>
									<th class="description">Description</th>
								</tr>
								<tr>
									<th><kbd>$table</kbd></th>
									<td><em>string</em></td>
									<td><em>required</em></td>
									<td>the table name</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<th>Returns</th>
						<td>Returns the current instance.</td>
					</tr>
					<tr>
						<th>Example</th>
						<td>
							<pre class="php"><code>// prepare an insert statement
$query = DB::insert('users');

// Update the table to insert into
$query->table('admins');

// INSERT INTO `admins` ...
</code></pre>
						</td>
					</tr>
				</tbody>
			</table>
		</article>
		
		<article>
			<h4 id="method_columns">columns(array $columns)</h4>
			<p>The <strong>columns</strong> method sets/changes the columns to insert.</p>
			<table class="method">
				<tbody>
					<tr>
						<th>Static</th>
						<td>No</td>
					</tr>
					<tr>
						<th>Parameters</th>
						<td>
							<table class="parameters">
								<tr>
									<th>Param</th>
									<th>Type</th>
									<th>Default</th>
									<th class="description">Description</th>
								</tr>
								<tr>
									<th><kbd>$columns</kbd></th>
									<td><em>array</em></td>
									<td><em>required</em></td>
									<td>an array of column names</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<th>Returns</th>
						<td>Returns the current instance.</td>
					</tr>
					<tr>
						<th>Example</th>
						<td>
							<pre class="php"><code>// prepare an insert statement
$query = DB::insert('users');

// Set the columns
$query->columns(array(
	'name',
	'surname',
	'email)
);

// INSERT INTO `users` (`name`, `surname`, `email`) 
</code></pre>
						</td>
					</tr>
				</tbody>
			</table>
		</article>

		<article>
			<h4 id="method_values">values(array $values)</h4>
			<p>The <strong>values</strong> method appends the values to insert.</p>
			<table class="method">
				<tbody>
					<tr>
						<th>Static</th>
						<td>No</td>
					</tr>
					<tr>
						<th>Parameters</th>
						<td>
							<table class="parameters">
								<tr>
									<th>Param</th>
									<th>Type</th>
									<th>Default</th>
									<th class="description">Description</th>
								</tr>
								<tr>
									<th><kbd>$values</kbd></th>
									<td><em>array</em></td>
									<td><em>required</em></td>
									<td>list of values</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<th>Returns</th>
						<td>Returns the current instance.</td>
					</tr>
					<tr>
						<th>Example</th>
						<td>
							<pre class="php"><code>// prepare an insert statement
$query = DB::insert('users');

// Set the columns
$query->clumns(array(
	'name',
	'surname',
	'email',
));

// Set the values

$query->values(array(
	'John',
	'Doe',
	'john@doe.com',
));

// INSERT INTO `users` (`name`, `surname`, `email`) VALUES ("John", "Doe", "john@doe.com")
</code></pre>
						</td>
					</tr>
				</tbody>
			</table>
		</article>
		
		<article>
			<h4 id="method_set">set(array $pairs)</h4>
			<p>The <strong>set</strong> method sets the columns and appends the values to insert.</p>
			<table class="method">
				<tbody>
					<tr>
						<th>Static</th>
						<td>No</td>
					</tr>
					<tr>
						<th>Parameters</th>
						<td>
							<table class="parameters">
								<tr>
									<th>Param</th>
									<th>Type</th>
									<th>Default</th>
									<th class="description">Description</th>
								</tr>
								<tr>
									<th><kbd>$pairs</kbd></th>
									<td><em>array</em></td>
									<td><em>required</em></td>
									<td>associative array of columns and values</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<th>Returns</th>
						<td>Returns the current instance.</td>
					</tr>
					<tr>
						<th>Example</th>
						<td>
							<pre class="php"><code>// prepare an insert statement
$query = DB::insert('users');

// Set the columns and vales
$query->set(array(
	'name' => 'John',
	'surname' => 'Doe',
	'email' => 'john@doe.com',
));

// INSERT INTO `users` (`name`, `surname`, `email`) VALUES ("John", "Doe", "john@doe.com")
</code></pre>
						</td>
					</tr>
				</tbody>
			</table>
		</article>
		
		<article>
			<h4 id="method_compile">compile(\Database_Connection$db)</h4>
			<p>The <strong>limit</strong> method returns the insert SQL query as a string.</p>
			<table class="method">
				<tbody>
					<tr>
						<th>Static</th>
						<td>No</td>
					</tr>
					<tr>
						<th>Parameters</th>
						<td>
							<table class="parameters">
								<tr>
									<th>Param</th>
									<th>Type</th>
									<th>Default</th>
									<th class="description">Description</th>
								</tr>
								<tr>
									<th><kbd>$db</kbd></th>
									<td><em>object</em></td>
									<td><em>required</em></td>
									<td>A database connection</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<th>Returns</th>
						<td>Returns the SQL query as a string.</td>
					</tr>
					<tr>
						<th>Example</th>
						<td>
							<pre class="php"><code>// prepare an insert statement
$query = DB::select('*')->from('users');

// Set the limit and offset
$query->limit(10);
$query->offset(5);

// Get the database connection
$connection = Database_Connection::instance();

// Get the sql query
$sql = $query->compile($connection);
</code></pre>
						</td>
					</tr>
				</tbody>
			</table>
		</article>
		
		<article>
			<h4 id="method_reset">reset()</h4>
			<p>The <strong>reset</strong> method resets all values of the current instance.</p>
			<table class="method">
				<tbody>
					<tr>
						<th>Static</th>
						<td>No</td>
					</tr>
					<tr>
						<th>Parameters</th>
						<td>
							<em>None</em>
						</td>
					</tr>
					<tr>
						<th>Returns</th>
						<td>Returns the current instance.</td>
					</tr>
					<tr>
						<th>Example</th>
						<td>
							<pre class="php"><code>// prepare an insert statement
$query = DB::insert('users');

// Set some values
$query->set(array(
	'name' => 'John',
	'surname' => 'Doe',
));

// Reset it
$query->reset();

// Set the new values
$query->table('admins')->set(array(
	'name' => 'Mark',
	'surname' => 'Handriks'
));

// The SQL query will now be:
// INSERT INTO `admins` (`name`, `surname`) VALUES ("Mark", "Hendriks")
</code></pre>
						</td>
					</tr>
				</tbody>
			</table>
		</article>
				
	</section>

	<section id="footer">
		<p>
			<a href="http://fuelphp.com">Fuel</a> is released under the MIT license.<br />
			&copy; 2010 - 2011 Fuel Development Team
		</p>
	</section>

</body>
</html>
